 <template>
  <div class="padding flex direction-column height-100">
    <div class="search-form">
      <el-form inline>
        <year-month-picker v-model="time"></year-month-picker>
        <el-form-item label="所属区域">
          <el-select v-model="area">
            <el-option
              v-for="option in districts" :key="option.code"
              :label="option.name" :value="option.code"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" @click="onSearch">查询</el-button>
        </el-form-item>
      </el-form>
    </div>
    <div class="flex-1 overflow-auto dark-table-wrapper">
      <el-table
        v-loading="loading"
        :data="lists" height="100%"
        :header-cell-style="{
          backgroundColor: themeColor,
          color: 'white'
        }"
      >
        <div slot="empty" class="empty-lists">
          <i class="i-custom:search"></i>
          <span class="empty-text">暂无数据</span>
        </div>
        <el-table-column type="index" label="排名"></el-table-column>
        <el-table-column v-for="column in columns" :key="column.prop" v-bind="column">
          <template v-if="column.prop === 'col1'" #default="{ row }">
            <el-link :underline="false" type="primary" @click="navigateToEnterpriseAnalysis(row)">{{row.col1}}</el-link>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <el-pagination
      class="pagination" layout="total,prev,pager,next"
      hide-on-single-page background
      :current-page.sync="pagination.pageNumber" :page-size="pagination.pageSize"
      :total="pagination.total"
      @current-page="getLists"
    ></el-pagination>
  </div>
</template>

<script>
import TimePicker from '@/mixins/time-picker'
import Navigate2enterpriseAnalysis from '@/mixins/navigate2enterpriseAnalysis'

export default {
  name: 'energy-efficiency-analysis-consumption-rank',
  mixins: [TimePicker, Navigate2enterpriseAnalysis],
  data () {
    return {
      area: '',
      loading: false,
      lists: [],
      columns: [
        { label: '区域', prop: 'col1' },
        { label: '综合能源消费量（吨标准煤）', prop: 'col3' },
        { label: '用电量（吨标准煤）', prop: 'col5' },
        { label: '用煤量（吨）', prop: 'col6' },
        { label: '天然气（立方米）', prop: 'col7' },
        { label: '能源消费总量（吨标准煤）', prop: 'col8' },
      ],
      pagination: {
        pageNumber: 1,
        pageSize: 13,
        total: 0
      }
    }
  },
  computed: {
    themeColor () {
      return this.$store.state.user.theme
    },
    qs () {
      return {
        time: this.time,
        area: this.area
      }
    },
    districts () {
      return this.$store.getters['user/districts']
    },
  },
  mounted () {
    this.getLists()
  },
  methods: {
    getLists () {
      this.loading = true
      // TODO
      return new Promise((resolve) => {
        this.loading = false
        resolve()
        this.lists = this.districts.map(v => ({
          id: v.code,
          col1: v.name,
          col2: '-',
          col3: '-',
          col4: '-',
          col5: '-',
          col6: '-',
          col7: '-',
          col8: '-',
        }))
      })
    },
    onSearch () {
      this.pagination.pageNumber = 1
      this.$nextTick(() => {
        this.getLists()
      })
    },
  }
}
</script>

<style scoped>

</style>
